package yingyong;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;

public class demo2 {
    public static void main(String[] args) {
        /*
        需求：
        集合里一下的数字，把他们变成Int类型
        "1","2","3","4","5"

         */
        //1.常规方法
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "1", "2", "3", "4", "5");
        ArrayList<Integer> list2 = new ArrayList<>();
        for (String s : list1) {
            int i = Integer.parseInt(s);
            list2.add(i);
        }
        System.out.println(list2);
        System.out.println("---------------");
        //2.stream流
        list1.stream().map(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                int i = Integer.parseInt(s);
                return i;
            }
        }).forEach(s-> System.out.println(s));
        System.out.println("---------------");
        //简化lambda表达式
        list1.stream().map( s-> Integer.parseInt(s)).forEach(s-> System.out.println(s));
        System.out.println("---------------");
        //3.引用类方法
        list1.stream().map(Integer::parseInt).forEach(s-> System.out.println(s));

    }
}
